package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import com.rc.entity.web.PageParam;
import com.rc.entity.web.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;

@RestController
@Api(tags="$(table.comment)")
@RequestMapping("/${entity?uncap_first}")
public class ${entity}Controller {

    @Autowired
    private ${table.serviceName} ${entity?uncap_first}Service;

    /**
    * 根据id获取对象
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    public ${entity} getById(@PathVariable Long id) {
        return ${entity?uncap_first}Service.getById(id);
    }

    /**
    * 分页查询
    * @param pageParam
    * @return
    */
    @PostMapping("/queryByPage")
    public Result queryUserByPage(PageParam pageParam){
        QueryWrapper<${entity}> ${entity?uncap_first}QueryWrapper = new QueryWrapper<>();
        Map<String, String> queryMap = pageParam.getQueryMap();
        if (StringUtils.isNotBlank(queryMap.get("id"))){
            ${entity?uncap_first}QueryWrapper.like("id",queryMap.get("id"));
        }
        Page<${entity}> ${entity?uncap_first}Page = ${entity?uncap_first}Service.page(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), ${entity?uncap_first}QueryWrapper);
        return Result.SUCCESS(${entity?uncap_first}Page);
    }
}
